package com.dlc.beijingrfid.net.protocol;

import android.util.Log;

import com.dlc.beijingrfid.net.bean.SimpleBean;
import com.dlc.beijingrfid.net.protocol.base.HttpProtocol;
import com.lzy.okgo.model.HttpParams;
import rx.Observable;

/**
 * 用来复制粘贴做模板的类
 */
public class TagProto extends HttpProtocol {

    private TagProto() {
    }

    private static class InstanceHolder {
        private static final TagProto sProtocol = new TagProto();
    }

    public static TagProto get() {
        return InstanceHolder.sProtocol;
    }

    /**
     * 绑定标签
     *
     * @param productId 产品id
     * @param rfids rfid
     * @return
     */
    public Observable<SimpleBean> bindRFID(int productId,int departments_Id,int user_id, String... rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("goods_id", productId);
        httpParams.put("office_id", departments_Id);
        if (user_id != 0){
            httpParams.put("user_id", user_id);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rfids.length; i++) {

            sb.append(rfids[i]);

            if (i != rfids.length - 1) {
                sb.append(',');
            }
        }
        httpParams.put("rfids", sb.toString());

        return rxPost("rfid_bind", httpParams, SimpleBean.class, true, null);
    }

    /**
     * 解绑RFID
     *
     * @param reason 原因
     * @param type 解除类型：1标签损坏；2布草损坏
     * @param rfids rfid,多个时以逗号隔开
     * @return
     */
    public Observable<SimpleBean> unbindRFID(String reason, int type, String... rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("reason", reason);
        httpParams.put("type", type);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rfids.length; i++) {

            sb.append(rfids[i]);

            if (i != rfids.length - 1) {
                sb.append(',');
            }
        }
        httpParams.put("ids", sb.toString());
        Log.e("MainA",sb.toString());

        return rxPost("rfid_kill", httpParams, SimpleBean.class, true, null);
    }
}
